package programs;

import java.io.IOException;

public class LosslessCompressionDemo 
{

	public static void main(String[] args) throws IOException
	{
		//BufferedImage bf = new BinaryAsBilevel().toBilevelImage(new File("config/pics/binarycodes/01_wahet_texture_qsw_code.bmp"));
		//ImageIO.write(bf , "bmp", new File("config/pics/binarycodes/bilevel.bmp"));
//		String input = "010101_wahet_texture_cr_code";
//		System.out.format("file name: %s\nsegmentation algorithm: %s\nfeature extraction algorithm: %s\n",
//						   StringParser.getOriginalFileName(input), StringParser.getSegmentationAlgorithm(input), StringParser.getFeatureExtractionAlgorithm(input));
//		try
//		{
//			// Directories relative to eclipse-path
//			File softwareDir 			= new File("config\\software\\USIT\\bin");			
//			File imgDir 				= new File("config\\pics");
//			File sourceImgDir			= new File("config\\pics\\source");
//			File segmentationImgDir 	= new File("config\\pics\\segmentation");
//			File binarycodesImgDir 		= new File("config\\pics\\binaryCodes");
//
//			File BZip2CompressedImgDir	= new File("config\\pics\\BZip2_compressed");
//			File GZipCompressedImgDir	= new File("config\\pics\\Gzip_compressed");
//			File ZipCompressedImgDir	= new File("config\\pics\\Zip_compressed");
//			File XZCompressedImgDir		= new File("config\\pics\\XZ_compressed");
//			File JBIG2CompressedImgDir 	= new File("config\\pics\\JBIG2_compressed");
//
//			// Create new ImageHandler and set Directories
//			ImageHandler imgHdl = new ImageHandler(imgDir, sourceImgDir, segmentationImgDir, binarycodesImgDir, softwareDir);
//			// Read the source-Images and execute all Segmentations
//			imgHdl.readSource();
//			System.out.println("Images read from config/pics/source, segmented using caht.exe and wahet.exe and saved into config/pics/segmented");
//			// Read the segmented Images and execute all Feature Extractions
//			imgHdl.readSegmentation();
//			System.out.println("Images read from config/pics/segmentation, extracted features using lg.exe, qsw.exe... and saved into config/pics/binarycodes");
//			// Read in the Binary Images!!
//			File[] binaryCodes = imgHdl.getBinaryCodes();
//			System.out.println("Images read from config/pics/binarycodes and provided for Compression");
//
//
//			// For each Binary Image, encode with all algorithms and save them
//			for (File f : binaryCodes) {
//				File outputBZip2 			= new File(BZip2CompressedImgDir + "\\" + f.getName().substring(0, f.getName().length()-4) + "_compressed.bzip2");
//				File outputGZip 			= new File(GZipCompressedImgDir + "\\" + f.getName().substring(0, f.getName().length()-4) + "_compressed.gzip");
//				File outputZip 				= new File(ZipCompressedImgDir + "\\" + f.getName().substring(0, f.getName().length()-4) + "_compressed.zip");
//				File outputXZ 				= new File(XZCompressedImgDir + "\\" + f.getName().substring(0, f.getName().length()-4) + "_compressed.xz");
//				File outputJBIG2 			= new File(JBIG2CompressedImgDir + "\\" + f.getName().substring(0, f.getName().length()-4) + "_compressed.jbig2");
//
//				new Bzip2().encode(f, outputBZip2);
//				new GZip().encode(f, outputGZip);
//				new Zip().encode(f, outputZip);
//				new XZ().encode(f, outputXZ);
//				new JBIG2().encode(f, outputJBIG2);
//
//				System.out.println("Compression of file " + f.getName() + " successful");
//			}
//			// For Debugging
//			System.out.format("Komprimierung beendet");
//		}
//		catch(IOException e)
//		{
//			System.out.format("Caught exception:\n%s\n", e.toString());
//		}
//		catch (InterruptedException i)
//		{
//			System.out.format("Caught exception:\n%s\n", i.toString());
//		}
	}

}
